<?php
/*
Code copyright (c) R-Sully www.r-sully.com
	By using this code you agree to keep the above license and this message
*/
// Timer class to keep track of page load times
class Timer
{
	private $beginTime = 0, $endTime = 0, $timing = false;
	function __construct($begin = true)
	{
		if($begin === true)
			$this->startTimer();
	}
	public function startTimer()
	{
		$this->timing = true;
		$this->beginTime = microtime(true);
	}
	public function endTimer()
	{
		$this->timing = false;
	}
	public function getTimeString()
	{
		$time = $this->getTime();
		$timeStr = sprintf("%0.4f", $time);
		$returnStr = $timeStr . " second";
		if($time != 1)
			$returnStr .= "s";
		return $returnStr;
	}
	public function getTime()
	{
		if($this->beginTime == 0)
			$beginTime = microtime(true);
		else
			$beginTime = $this->beginTime;
		if($this->endTime == 0)
			$endTime = microtime(true);
		else
			$endTime = $this->endTime;
		return ($endTime - $beginTime);
	}
}
?>